package com.ycw.servlet.laowei;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ycw.dao.HouseDao;
import com.ycw.dao.impl.HouseDaoImpl;
import com.ycw.pojo.House;

/**
 * Servlet implementation class HouseDeleteByIdServlet
 */
@WebServlet("/HouseDeleteByIdServlet")
public class HouseDeleteByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public HouseDeleteByIdServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);

		// 通过id删除
		HouseDao hDao = new HouseDaoImpl();
		Integer hid = Integer.parseInt(request.getParameter("h_id"));

		House house = new House();
		house.setH_id(hid);
		int i = hDao.deleteHouseInfo(house);
		boolean f = false;
		if (i > 0) {
			f = true;
		}
		// 向前端发送JSON数据
		String resJSON = JSON.toJSONString(f);
		PrintWriter out = response.getWriter();
		out.write(resJSON);
		out.close();

	}

}
